package com.crawler.parser;

import java.util.Date;
import java.util.Map;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.google.common.collect.Maps;

public class UserInfoPageParser extends ParserAdapter {

	/**
	 * 解析用户信息
	 */
	@Override
	public Map<String, Object> parseMap(String html) {
		Document doc = Jsoup.parse(html);
		Element userInfo = doc.getElementById("user-info");
		Elements strongs = doc.select("strong");
		String email = strongs.first().text();
		String userId = userInfo.select("b").first().text();//用户名：15652676061_p
		userId = userId.substring(userId.indexOf("：")+1,userId.length());
		String gradeLevel = userInfo.select("a").get(1).text();
		String gradeType = userInfo.select("div.shop-level").first().nextElementSibling().text();//会员类型：个人用户
		gradeType = gradeType.substring(gradeType.indexOf("：")+1,gradeType.length());
		String realName = doc.getElementById("realName").val();
		String nickName = doc.getElementById("nickName").val();
		
		Map<String, Object> map = Maps.newHashMap();
		map.put("customerID", userId);
		map.put("realName", realName);
		map.put("nickName", nickName);
		map.put("email", email);
		map.put("gradeType", gradeType);
		map.put("gradeLevel", gradeLevel);
		map.put("mobile", "");
		map.put("registerTime", "");
		map.put("shopLevel", "");
		map.put("createTime", new Date());
		return map;
	}
	
}
